package com.wq.recruit.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wq.recruit.entity.Enterprise;
import com.wq.recruit.mapper.EnterpriseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EnterpriseService {
    @Autowired
    private EnterpriseMapper enterpriseMapper;

    public List<Enterprise> hotList(String ishot) {
//        查询企业表ishot字段为1的记录
        QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(null != ishot, "ishot", ishot);
        return enterpriseMapper.selectList(queryWrapper);
    }

    public Page<Enterprise> search(Map map, int page, int size) {
//根据ishot是否热门完全匹配，address模糊查询，name模糊查询,address和name满足其一即可
        QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(null != map.get("ishot"), "ishot", map.get("ishot"))
                .and(wapper -> wapper.like(null != map.get("address"), "address", map.get("address"))
                        .or().like(null != map.get("name"), "name", map.get("name")));
        Page<Enterprise> enterprisePage = new Page<>(page, size);
        return enterpriseMapper.selectPage(enterprisePage, queryWrapper);
    }
}